package com.greenold.check.controller;

import com.greenold.check.domain.Checkin;
import com.greenold.check.domain.Dto.CheckInConfigDto;
import com.greenold.check.domain.Dto.CheckinDto;
import com.greenold.check.domain.Dto.ContractDto;
import com.greenold.check.domain.Vo.CheckinVo;
import com.greenold.check.service.ICheckinService;
import com.greenold.commen.domain.Dto.ElderDto;
import com.greenold.commen.domain.Elder;
import com.greenold.commen.service.WorkFlowServie;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.core.page.TableDataInfo;
import com.greenold.common.enums.BusinessType;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.residing.domain.Contract;
import com.greenold.system.mapper.SysDeptMapper;
import com.greenold.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 入住办理Controller
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/check/checkin")
public class CheckinController extends BaseController
{
    @Autowired
    private ICheckinService checkinService;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private SysDeptMapper deptMapper;
    @Autowired
    private WorkFlowServie workFlowServie;

    /**
     * 查询入住办理列表
     */
    @PreAuthorize("@ss.hasPermi('system:checkin:list')")
    @GetMapping("/list")
    public TableDataInfo list(Checkin checkin)
    {
        startPage();
        List<Checkin> list = checkinService.selectCheckinList(checkin);
        return getDataTable(list);
    }
    /**
     *
     *
    * 查询入住列表
    * */
    @PreAuthorize("@ss.hasPermi('system:checkin:list')")
    @GetMapping("/list1")
    public TableDataInfo list1(CheckinDto checkinDto)
    {
        System.out.println(checkinDto.toString());
        startPage();
        List<CheckinDto> list = checkinService.selectCheckinDtoList(checkinDto);

        return getDataTable(list);
    }


    /**
     * 导出入住办理列表
     */
    @PreAuthorize("@ss.hasPermi('system:checkin:export')")
    @Log(title = "入住办理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Checkin checkin)
    {
        List<Checkin> list = checkinService.selectCheckinList(checkin);
        ExcelUtil<Checkin> util = new ExcelUtil<Checkin>(Checkin.class);
        util.exportExcel(response, list, "入住办理数据");
    }

    /**
     * 获取入住办理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:checkin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(checkinService.selectCheckinDtoById(id));
    }

    /**
     * 新增入住办理
     */
    @PreAuthorize("@ss.hasPermi('system:checkin:add')")
    @Log(title = "入住办理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckinVo checkinVo)
    {
        return toAjax(checkinService.insertCheckin(checkinVo));
    }



    /**
     * 修改入住办理
     */
    @PreAuthorize("@ss.hasPermi('system:checkin:edit')")
    @Log(title = "入住办理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Checkin checkin)
    {
        return toAjax(checkinService.updateCheckin(checkin));
    }

    /**
     * 删除入住办理
     */
    @PreAuthorize("@ss.hasPermi('system:checkin:remove')")
    @Log(title = "入住办理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(checkinService.deleteCheckinByIds(ids));
    }
    /*
    * 申请入住请求
    * */
    @PostMapping("/create")
    public AjaxResult create(@RequestBody Elder elder) {
        return checkinService.create(elder);
    }
    /*
    * 入住表单查询
    * */
//    @GetMapping("/getCheckin")
//    public AjaxResult getCheckIn(String assigneeId,String code,Integer flowStatus,String taskId) {
//        return success(checkinService.getCheckIn(assigneeId,code,flowStatus,taskId));
    //回显数据
    @GetMapping("/getElderInfo")
    public AjaxResult getElderInfo(@RequestParam String bussinessId) {
        return checkinService.getElderInfo(bussinessId);
    }
    /*
    * 护理主管评估
    * */
        @PostMapping("/review")
        public AjaxResult review(@RequestBody Map<String, Object> data) {
            return checkinService.review(data);
        }
    /*
    * 副院长审批
    * */
    @PutMapping("/submit")
    public AjaxResult submit(@RequestParam String businessId, @RequestParam String message, @RequestParam String taskId,@RequestParam Integer shenHE) {
        System.out.println(businessId);
        System.out.println(message);
        System.out.println(taskId);
        System.out.println(shenHE);
        return checkinService.submit(businessId, message, taskId, shenHE);
    }
    /*
     * 养老顾问入住配置
     * */
    @PostMapping("checkInConfig")
    public AjaxResult checkInConfig(@RequestBody CheckInConfigDto checkInConfigDto) {
        return success(checkinService.checkInConfig(checkInConfigDto));
    }
    /*
     * 法务人员签约办理
     * */
    @PostMapping("/sign")
    public AjaxResult sign(@RequestBody ContractDto contractDto) {
        System.out.println(contractDto);
        return checkinService.sign(contractDto);
    }
    /*
    * 审批记录查询
    * */
    @GetMapping("/getApprovalRecord")
    public AjaxResult getApprovalRecord(@RequestParam String businessId) {
        List<Map<String, Object>> historyTaskList = workFlowServie.getHistoryTaskList(businessId);
        return success(historyTaskList);
    }
    /*
    * 入住配置的护理等级列表和空闲床位号列表
    * */
    @GetMapping("/getCareLevelAndBedList")
    public AjaxResult getCareLevelAndBedList() {
        return checkinService.getCareLevelAndBedList();
    }
}
